import request from '@/utils/request'

/**
 * 分页查询员工信息
 *
 * @param {*} query
 */
export function getStaffList(query) {
  return request({
    url: '/smsk/admin/staff/list',
    method: 'get',
    params: query
  })
}

/**
 * 创建员工
 * @param {*} staffInfo
 */
export function createStaffInfo(staffInfo) {
  return request({
    url: '/smsk/admin/staff/create',
    method: 'post',
    data: staffInfo
  })
}

/**
 * 更新员工信息
 * @param {*} staffInfo
 */
export function updateStaffInfo(staffInfo) {
  return request({
    url: '/smsk/admin/staff/update',
    method: 'post',
    data: staffInfo
  })
}

/**
 * 获取员工信息
 * @param {*} id 
 * @returns 
 */
export function getUserInfo(params) {
  return request({
    url: '/smsk/admin/staff/details',
    method: 'get',
    params: params
  })
}

/**
 * 根据员工ID删除员工
 *
 * @param {*} staffId
 */
export function deleteStaffInfo(params) {
  return request({
    url: '/smsk/admin/staff/delete',
    method: 'post',
    params: params
  })
}

/**
 * 解锁员工
 * @param {*} staffId
 */
export function unlockStaff(staffId) {
  return request({
    url: '/smsk/admin/staff/unlock',
    method: 'post',
    params: { staffId }
  })
}

export function importStaffInfo(fileobj, obj) {
  if (!fileobj || !fileobj.file) {
    return {}
  }
  const param = new FormData()
  if (obj) {
    for (const key in obj) {
      param.append(key, obj[key])
    }
  }
  param.append('file', fileobj.file)
  return request({
    method: 'post',
    url: '/smsk/admin/staff/import',
    headers: { 'Content-Type': 'multipart/form-data' },
    data: param
  })
}

export function exportStaffInfo(query) {
  return request({
    url: '/smsk/admin/staff/export',
    method: 'get',
    params: query
  })
}

export function exportStaffInfoTemplate() {
  return request({
    url: '/smsk/admin/staff/exportTemplate',
    method: 'get'
  })
}
/**
 * 修改员工密码
 * @param {*} staffId
 * @param {*} newPasswd
 */
export function changePasswd(params) {
  return request({
    url: '/smsk/admin/staff/passwd/change',
    method: 'post',
    data: params
  })
}
